package com.yyq.adms.usermanage.action;

import java.io.UnsupportedEncodingException;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.yyq.adms.usermanage.bpo.SysRolesBpo;
import com.yyq.adms.usermanage.pojo.SysRoles;
import com.yyq.sos.action.BaseAction;

@Controller("sysRolesAction")
@Scope("prototype")
public class SysRolesAction extends BaseAction {
	
	SysRoles po = new SysRoles();
	private SysRolesBpo bpo;

	
	@Resource(name="sysRolesBpo")
	public void setBpo(SysRolesBpo bpo) {
		bpo.setCls(po.getClass());
		this.bpo = bpo;
	}

	/**
	 * Action操作入口
	 */
	public String execute() throws Exception {
		super.setBpo(bpo);
		super.setObj(po);
		return super.execute();
	}
	
	public String goUpdate() {
		po = (SysRoles) bpo.findByPk(po.getId());
		return super.goUpdate();
	}
	
	public String search() {
		String value = ((String[]) this.getFormValue("key"))[0];
		try {
			value = new String(value.getBytes("ISO-8859-1"), "GB18030");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		if (value != null && !value.trim().equals("")) {
			this.setFormData(bpo.searchPage(new String[] { "roleName",
					"roleCname"}, new String[] { value }, this
					.getPageForm().getPageNo(), this.getPageForm()
					.getPageSize()));
		}
		return super.search();
	}

	public SysRoles getPo() {
		return po;
	}

	public void setPo(SysRoles po) {
		this.po = po;
	}
}
